{include file="common/mini-header" title="权限节点"}
<div class="layui-body">
	<!-- 内容主体区域 -->

	<form class="layui-form" action="" style="max-width: 800px;width: 90%;">
		<div class="layui-form-item">
			<label class="layui-form-label">所属类型</label>
			<div class="layui-input-block">
				{if condition="$ruleInfo['type'] eq 'node'"}
				<input type="radio" name="type" disabled value="node" title="节点" checked>
				{elseif  condition="$ruleInfo['type'] eq 'menu'"}
				<input type="radio" name="type" disabled value="menu" title="菜单" checked>
				{else /}
				{/if}
			</div>
		</div>
		{if condition="$ruleInfo['type'] eq 'menu'"}
		<div class="layui-form-item">
			<label class="layui-form-label">父级菜单</label>
			<div class="layui-input-inline" style="width: 200px;">
				<select name="pid" lay-verify="required">
					<option value="0">一级菜单</option>
					{volist name="menuList" id="item"}
					{if condition="$item.id eq $ruleInfo['id']"}
					{elseif condition="$item.id eq $ruleInfo['pid']" /}
					<option value ="{$item.id}" selected>{$item.name}</option>
					{else /}
					<option value ="{$item.id}">{$item.name}</option>
					{/if}
					{/volist}
				</select>
			</div>
		</div>
		{else /}
		<input type="hidden" name="pid" value="{$ruleInfo['pid']}" />	
		{/if}	
		<div class="layui-form-item">
			<label class="layui-form-label">节点名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" required lay-verify="required" placeholder="请输入菜单名称" value="{$ruleInfo['name']}" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">节点链接</label>
			<div class="layui-input-block">
				<input type="text" name="rules" required lay-verify="required" placeholder="请输入url或者节点(/admin/控制器/方法)" value="{$ruleInfo['rules']}" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" name="id" id="ruleId" value="{$ruleInfo['id']}" />
				<button class="layui-btn" lay-submit lay-filter="addBtn">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				<button class="layui-btn layui-btn-danger" type="button" style="float:right" id="delBtn" >删除</button>
			</div>
		</div>
	</form> 

</div>
<script>
	layui.use('form', function() {
		var form = layui.form;
		var $ = layui.jquery;
		var layer = layui.layer;
		var ruleId = $('#ruleId').val(); 

		//监听提交
		form.on('submit(addBtn)', function(data) {
			$.post('./editRule', data.field, function(rs) {
				if (rs.code>0) {
					layer.msg(rs.msg)
					setTimeout(function() { 
						parent.location.reload();
					}, 1000)
				} else {
					layer.alert(rs.msg)
				}
			})
			return false;
		});
		
		$(document).ready(function(){
			$('#delBtn').on('click',function(){
				layer.confirm('确定删除吗?', function(index){
				  if(index == 1){ //确定
					  $.ajax({
						url: './delete',
						type: 'DELETE',
						data: {id:ruleId},
						success:function(rs){
							layer.msg(rs.msg)
							if(rs.code == 1){ 
								setTimeout(function() { 
									parent.location.reload();
								}, 400)
							}
						}
					  }); 
				  }
				  layer.close(index);
				});       
			})
		})
	});
</script>
{include file="common/footer"}
